<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const value = {
        msg: "ok",
        arr: [1, 2, 3, [4, 5]],
        bool: true,
        obj: {
          msg: "success",
          obj2: {
            arr2: [2, 3, 4],
          },
        },
      };
      function deepCopy(value) {
        if (typeof value !== "object") {
          return value;
        }

        const res = Array.isArray(value) ? [] : {};

        for (let key in value) {
          if (value.hasOwnProperty(key)) {
            res[key] = deepCopy(value[key]);
          }
        }

        return res;
      }

      console.log(deepCopy(value));
    </script>
  </body>
</html>
